<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>更新宿舍</title>

    <!-- Bootstrap -->
    <link href="<%=request.getContextPath() %>/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath() %>/static/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath() %>/static/css/jumbotron.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="<%=request.getContextPath() %>/static/js/html5shiv.min.js"></script>
      <script src="<%=request.getContextPath() %>/static/js/respond.min.js"></script>
    <![endif]-->
    
    <script type="text/javascript">
		function submitForm() {
			var institute = document.getElementById("institute");
			var domitory = document.getElementById("domitory");
			var domitorycount = document.getElementById("domitorycount");
			var adddomitoryForm=document.getElementById("adddomitoryForm");
			
			if (institute.value == 0) {
				alert("请选择机构！");
				institute.focus();
				return false;
			}
			if (domitory.value=="") {
				alert("宿舍号不能为空！");
				domitory.focus();
				return false;
			}
			if(domitorycount.value==0){
				alert("请选择寝室满员人数！");
				domitorycount.focus();
				return false;
			}
			adddomitoryForm.submit();
			
			return true;
		}

    </script>
</head>

<body>
<jsp:include page="../Common/navHeader.jsp"></jsp:include>


<div class="container">
<h1 style="font-family:华文行楷;" >好室友<small>网</small> </h1>
<div class="row">
<div class="col-sm-2">
</div>
<div class="col-sm-6">
<form class="form-horizontal" method="post" id="adddomitoryForm" onsubmit="return submitForm();">
		
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-4 control-label">所在单位名：</label>
    <div class="col-sm-8">
      	<c:if test="${universities ne null }">
  			<select class="form-control" id="institute" name="institute">
  				<option value="0">请选择所在机构</option>
  				<c:forEach var="item" items="${universities }">
  				<c:if test="${item.id eq allocation.universityid }">
  					<option selected value="${item.id }">${item.name}</option>
  				</c:if>
  				<c:if test="${item.id ne allocation.universityid }">
  					<option value="${item.id }">${item.name}</option>
  				</c:if>
  				</c:forEach>
  			</select>
  		</c:if>
  		<c:if test="${universities eq null }">
  			<select class="form-control" id="nation" name="nation">
  				<option value="0">机构加载失败</option>
  			</select>
  		</c:if>
    </div>
  </div>
  
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">宿舍号：</label>
    <div class="col-sm-8">
      <c:if test="${allocation ne null }">
      <input type="text" class="form-control" id="domitory" name="domitory" value="${allocation.domitoryid}" placeholder="宿舍号……">
      </c:if>
      <c:if test="${allocation eq null }">
      <input type="text" class="form-control" id="domitory" name="domitory"  placeholder="宿舍号……">
      </c:if>
    </div>
  </div>
  
  
  <div class="form-group">
     <label for="inputPassword3" class="col-sm-4 control-label">寝室满员人数：</label>
    	<div class="col-sm-8 dropdown">
    	<select class="form-control" id="domitorycount" name="domitorycount">
  			<option value="0">请选择人数</option>
  			<option value="1">1</option>
  			<option value="2">2</option>
  			<option value="3">3</option>
  			<option value="4">4</option>
  			<option value="5">5</option>
  			<option value="6">6</option>
  			<option value="7">7</option>
  			<option value="8">8</option>
  			<option value="9">9</option>
  			<option value="10">10</option>
		</select>
		</div>
  </div> 
   
  <div class="form-group">
    <div class="col-sm-offset-4 col-sm-8">
      <div class="col-sm-6">
      <button type="submit" class="btn btn-success">立即更新</button>
      </div>
      <div class="col-sm-6">
      <button type="reset" class="btn btn-warning">重新填写</button>
      </div>
    </div>
  </div>
  
  <div class="row">
  	<div class="col-sm-4"></div>
  	<div class="col-sm-8">
    <c:if test="${errorCode eq 0 }">
      <div class="alert alert-warning" role="alert" id="alert-warning">验证失败！</div>
    </c:if>
    <c:if test="${errorCode eq 1 }">
      <div class="alert alert-warning" role="alert" id="alert-warning">更新成功！</div>
    </c:if>
    <c:if test="${errorCode eq 2 }">
      <div class="alert alert-warning" role="alert" id="alert-warning">添加失败，该寝室人数已满！</div>
    </c:if>
    </div>
  </div>
  
  <input type="hidden" name="action" value="register" />
</form>
</div>
<div class="col-sm-4">
</div>
</div><!--<div class="row">-->
 
    <jsp:include page="../Common/Footer.jsp"></jsp:include>

</div><!--<div class="jumbotron">-->

	<script src="<%=request.getContextPath() %>/static/js/jquery.min.js" ></script>
	<script src="<%=request.getContextPath()%>/static/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="<%=request.getContextPath() %>/static/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
